version: "3.7"

services:
  minio:
    image: minio/minio:{{ minio_docker_config.version }}
    container_name: minio-{{ global_bond_ip | replace('.', '-') }}
    hostname: minio-{{ global_bond_ip | replace('.', '-') }}
    restart: always
    network_mode: host
    environment:
      MINIO_ROOT_USER: "{{ minio_docker_config.root }}"
      MINIO_ROOT_PASSWORD: "{{ minio_docker_config.pass }}"
      MINIO_STORAGE_CLASS_STANDARD: "EC:2"
      TIMEZONE: "Asia/Shanghai"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://minioip:9002/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3
    command:
      - "server"
      - "--address"
      - "minioip:9002"
      - "--console-address"
      - "minioip:9003"
      - "http://minio{1...{{ minio_count }}}:9002/opt/minio/data{1...{{ volumes_count }}}"
    extra_hosts:
      - "minioip:{{ global_bond_ip }}"
{% for minio in groups['minio'] %}
      - "minio{{ loop.index }}:{{ hostvars[minio]['global_bond_ip'] }}"
{% endfor %}
    volumes:
      - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime"
{% for vol in minio_volumes %}
      - "{{ vol }}:/opt/minio/data{{ loop.index }}"
{% endfor %}

  nginx:
    image: {{ nexus_docker_proxy | default('') }}nginx:stable
    hostname: minio-nginx
    container_name: minio-nginx
    environment:
      CONFIG_HASH: "{{ lookup('template', role_path + '/templates/nginx.conf.j2') | striptags | trim | hash('md5') }}"
      TIMEZONE: "Asia/Shanghai"
    volumes:
      - "/usr/share/zoneinfo/Asia/Shanghai:/etc/localtime"
      - "./nginx.conf:/etc/nginx/nginx.conf:ro"
    ports:
      - "9000:9000"
      - "9001:9001"
    depends_on:
      - minio
    extra_hosts:
{% for minio in groups['minio'] %}
      - "minio{{ loop.index }}:{{ hostvars[minio]['ansible_host'] | default(hostvars[minio]['inventory_hostname']) }}"
{% endfor %}
